package com.road2trip.datastore;

import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Place {

	@PersistenceCapable
	@EmbeddedOnly
	public static class PlaceKey {

		public PlaceKey(String name, String language) {
			this.name = name;
			this.language = language;
		}

		public PlaceKey(PlaceKey k) {
			this.name = k.name;
			this.language = k.language;
		}

		@Persistent
		private String name;

		@Persistent
		private String language;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getLanguage() {
			return language;
		}

		public void setLanguage(String language) {
			this.language = language;
		}

	}

	public enum PlaceType {
		COUNTRY, REGION, TOWN;

		@Override
		public String toString() {
			return this.name().toLowerCase();
		}
	}

	@PrimaryKey
	private PlaceKey key;

	@Persistent
	private String localizedName;

	@Persistent
	private PlaceType type;

	@Persistent
	private String parent;

	public Place(String name, String language) {
		this.key = new PlaceKey(name, language);
	}

	public Place(PlaceKey key) {
		this.key = key;
	}

	public PlaceKey getKey() {
		return key;
	}

	public void setKey(PlaceKey key) {
		this.key = key;
	}

	public String getLocalizedName() {
		return localizedName;
	}

	public void setLocalizedName(String localizedName) {
		this.localizedName = localizedName;
	}

	public PlaceType getType() {
		return type;
	}

	public void setType(PlaceType type) {
		this.type = type;
	}

	public void setType(String type) {
		this.type = PlaceType.valueOf(type.toLowerCase());
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

}
